{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "NLK_Code",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "vN5mzZtg4QbJ"
      },
      "source": [
        "import numpy as np"
      ],
      "execution_count": 65,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "U6O-eX6aNFx4"
      },
      "source": [
        "from scipy.optimize import minimize_scalar"
      ],
      "execution_count": 66,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OCJHVap7Hmfw"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 67,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CQPlpMsxMXmS"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[8]=p[8]+(1-b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range(10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 68,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "prIGJUulIi4y"
      },
      "source": [
        "result=minimize_scalar(NLK,method='bounded',bounds=[0.95, 1])"
      ],
      "execution_count": 69,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6Nw3QJjOJLO7",
        "outputId": "0158b4f9-235b-4f09-b1bb-779f7de2206e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "     fun: 1197.5555555555554\n",
              " message: 'Solution found.'\n",
              "    nfev: 6\n",
              "  status: 0\n",
              " success: True\n",
              "       x: 0.9777777777777785"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 70
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FD-cz-__KHz9"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 71,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2TfMBAnyOekB"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[7]=p[7]+5*(1-b)*(19-20*b)/(100-100*b)\n",
        "    p[8]=p[8]+5*(1-b)/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 72,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "x9v6HSMjO9Sg"
      },
      "source": [
        "result=minimize_scalar(NLK,method='bounded',bounds=[0.85, 0.95])"
      ],
      "execution_count": 73,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gA3oF7IrPB3W",
        "outputId": "d565897b-faaf-4fe2-c6db-99c886487439",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 74,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "     fun: 884.5152049944227\n",
              " message: 'Solution found.'\n",
              "    nfev: 20\n",
              "  status: 0\n",
              " success: True\n",
              "       x: 0.8500066106961353"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 74
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8IMOF0FPPJqW"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 75,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pRgloRMkPWKq"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[6]=p[6]+(1-b)*5*(17-20*b)/(100-100*b)\n",
        "    p[7]=p[7]+(1-b)*10/(100-100*b)\n",
        "    p[8]=p[8]+(1-b)*5/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 76,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "avgi_rsvPx4s"
      },
      "source": [
        "result=minimize_scalar(NLK,method='bounded',bounds=[0.70, 0.85])"
      ],
      "execution_count": 77,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2X6yAyDvP1xL",
        "outputId": "f385bf16-2016-4cf2-baf1-d6ec125252d5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 78,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "     fun: 382.01225724272365\n",
              " message: 'Solution found.'\n",
              "    nfev: 21\n",
              "  status: 0\n",
              " success: True\n",
              "       x: 0.7000061284523512"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 78
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GJiwq7oNP4GJ"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 79,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Y4Uq_z2TP7lq"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[5]=p[5]+(1-b)*5*(14-20*b)/(100-100*b)\n",
        "    p[6]=p[6]+(1-b)*15/(100-100*b)\n",
        "    p[7]=p[7]+(1-b)*10/(100-100*b)\n",
        "    p[8]=p[8]+(1-b)*5/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 80,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-R2XMJIwQimm"
      },
      "source": [
        "result=minimize_scalar(NLK,method='bounded',bounds=[0.50, 0.70])"
      ],
      "execution_count": 81,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ACeHoLEDQldY",
        "outputId": "2f705676-1ec6-49af-fa4a-f8a46f700fd3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 82,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "     fun: 382.0009657205298\n",
              " message: 'Solution found.'\n",
              "    nfev: 22\n",
              "  status: 0\n",
              " success: True\n",
              "       x: 0.6999951724460883"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 82
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ttAEyTz5Qm26"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 83,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "w8Wy1xarSGO_"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[4]=p[4]+(1-b)*5*(5-10*b)/(100-100*b)\n",
        "    p[5]=p[5]+(1-b)*5*(5-2*b)/(100-100*b)\n",
        "    p[6]=p[6]+(1-b)*5*(4-2*b)/(100-100*b)\n",
        "    p[7]=p[7]+(1-b)*5*(3-2*b)/(100-100*b)\n",
        "    p[8]=p[8]+(1-b)*5*(2-2*b)/(100-100*b)\n",
        "    p[9]=p[9]+(1-b)*5*(1-2*b)/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 84,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HibsoKxuR0xZ"
      },
      "source": [
        "result=minimize_scalar(NLK,method='bounded',bounds=[0, 0.50])"
      ],
      "execution_count": 85,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0dzli8YHTMsc",
        "outputId": "844e3c23-6fb0-41fb-c684-3b01c5aa9003",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 86,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "     fun: 782.0008032212256\n",
              " message: 'Solution found.'\n",
              "    nfev: 24\n",
              "  status: 0\n",
              " success: True\n",
              "       x: 0.49999553788108364"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 86
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lYbqsupCTNZS"
      },
      "source": [
        "b=0.70"
      ],
      "execution_count": 87,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "N4M4HdQGVSy6"
      },
      "source": [
        "p=np.zeros(10)"
      ],
      "execution_count": 88,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LU-nclh-VQsu"
      },
      "source": [
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[6]=p[6]+(1-b)*5*(17-20*b)/(100-100*b)\n",
        "    p[7]=p[7]+(1-b)*10/(100-100*b)\n",
        "    p[8]=p[8]+(1-b)*5/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100"
      ],
      "execution_count": 89,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VIkLHUhlVVTs",
        "outputId": "cd78648a-63c7-4804-efac-d5c16d1f9137",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "p"
      ],
      "execution_count": 90,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 7.,  7.,  7.,  7.,  7.,  7., 22., 17., 12.,  7.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 90
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "r0W_vID8VgA8"
      },
      "source": [
        "x=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 91,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fCRGK-U0WIio"
      },
      "source": [
        "def NLK(b):\n",
        "    for i in range(10):\n",
        "      p[i]=b/10\n",
        "    p[4]=p[4]+(1-b)*5*(5-10*b)/(100-100*b)\n",
        "    p[5]=p[5]+(1-b)*5*(5-2*b)/(100-100*b)\n",
        "    p[6]=p[6]+(1-b)*5*(4-2*b)/(100-100*b)\n",
        "    p[7]=p[7]+(1-b)*5*(3-2*b)/(100-100*b)\n",
        "    p[8]=p[8]+(1-b)*5*(2-2*b)/(100-100*b)\n",
        "    p[9]=p[9]+(1-b)*5*(1-2*b)/(100-100*b)\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(x[i]-p[i])**2\n",
        "    return L"
      ],
      "execution_count": 92,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ICUqOkwEWKcQ",
        "outputId": "715b41ee-8585-4028-a4ec-cc0540b64505",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "NLK(0)"
      ],
      "execution_count": 93,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "1372.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 93
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BBN15kp4WLPa",
        "outputId": "f1999be0-bc0f-428d-8977-81d398340377",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "p"
      ],
      "execution_count": 94,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 0.,  0.,  0.,  0., 25., 25., 20., 15., 10.,  5.])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 94
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BpMMGF1GWkLB"
      },
      "source": [
        "from scipy.optimize import minimize"
      ],
      "execution_count": 95,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_WeqnQAHRaaT"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 96,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TcQzb84GRcFj"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[8]=p[8]+(1-x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 97,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CNYxnq_jRd10"
      },
      "source": [
        "result=minimize(NLK,x0=[0.05,0.97],bounds=[[0,1],[0.95, 1]])"
      ],
      "execution_count": 98,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BopLEsEARfhL",
        "outputId": "eb8539e3-a8e8-4c6b-d1d1-aac103e91a4b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 99,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 119.75555555555562\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([1.42108547e-06, 0.00000000e+00])\n",
              "  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'\n",
              "     nfev: 18\n",
              "      nit: 5\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.97777776, 0.97777777])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 99
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rx8jbBcXRhI2",
        "outputId": "065dfb96-e757-443f-bc53-c047c567bd5e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        }
      },
      "source": [
        "p"
      ],
      "execution_count": 100,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 9.77777758,  9.77777758,  9.77777758,  9.77777758,  9.77777758,\n",
              "        9.77777758,  9.77777758,  9.77777758, 11.9999995 ,  9.77777758])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 100
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7gvUgcfURhwW"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 101,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hwMooCVrRkW6"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[7]=p[7]+5*(1-x[0])*(19-20*x[1])/(100-100*x[1])\n",
        "    p[8]=p[8]+5*(1-x[0])/(100-100*x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 102,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "npiu6L8HRl7G"
      },
      "source": [
        "result=minimize(NLK,x0=[0.05,0.90],bounds=[[0,1],[0.85, 0.95]])"
      ],
      "execution_count": 103,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aR3D759nRnU3",
        "outputId": "07d349ca-cd7d-45eb-d96f-64b15a71ed8b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 104,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 77.17560975609756\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([2.84217094e-06, 1.05936959e+02])\n",
              "  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'\n",
              "     nfev: 12\n",
              "      nit: 3\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.69268292, 0.85      ])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 104
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ONVGlziRRo3I"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 105,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nxarAaP0RqZJ"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[6]=p[6]+(1-x[0])*5*(17-20*x[1])/(100-100*x[1])\n",
        "    p[7]=p[7]+(1-x[0])*10/(100-100*x[1])\n",
        "    p[8]=p[8]+(1-x[0])*5/(100-100*x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 106,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "i2-JfWAlRsGm"
      },
      "source": [
        "result=minimize(NLK,x0=[0.05,0.80],bounds=[[0,1],[0.70, 0.85]])"
      ],
      "execution_count": 107,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Vip1wl45RteG",
        "outputId": "f540aae1-64c3-464b-bb03-9d4755ed4948",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 108,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 5.577777777778194\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([ 1.15463195e-05, -2.71782596e-05])\n",
              "  message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n",
              "     nfev: 33\n",
              "      nit: 9\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.34444447, 0.73423422])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 108
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Jg2xl2YvRvNV"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 109,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dENK-uZlRwtp"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[5]=p[5]+(1-x[0])*5*(14-20*x[1])/(100-100*x[1])\n",
        "    p[6]=p[6]+(1-x[0])*15/(100-100*x[1])\n",
        "    p[7]=p[7]+(1-x[0])*10/(100-100*x[1])\n",
        "    p[8]=p[8]+(1-x[0])*5/(100-100*x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 110,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3UQ_XEEORyPy"
      },
      "source": [
        "result=minimize(NLK,x0=[0,0.60],bounds=[[0,1],[0.50, 0.70]])"
      ],
      "execution_count": 111,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6os5aQ-5Rz0h",
        "outputId": "a8d8f50a-b4ea-4c1f-8cf4-6331a662071d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 112,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 7.471111111111398\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([-8.8817842e-07,  0.0000000e+00])\n",
              "  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'\n",
              "     nfev: 33\n",
              "      nit: 8\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.34222219, 0.6877637 ])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 112
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BZrfD87TR1Yn"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 113,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wGoVZbBgR3Lh"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[4]=p[4]+(1-x[0])*5*(5-10*x[1])/(100-100*x[1])\n",
        "    p[5]=p[5]+(1-x[0])*5*(5-2*x[1])/(100-100*x[1])\n",
        "    p[6]=p[6]+(1-x[0])*5*(4-2*x[1])/(100-100*x[1])\n",
        "    p[7]=p[7]+(1-x[0])*5*(3-2*x[1])/(100-100*x[1])\n",
        "    p[8]=p[8]+(1-x[0])*5*(2-2*x[1])/(100-100*x[1])\n",
        "    p[9]=p[9]+(1-x[0])*5*(1-2*x[1])/(100-100*x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 114,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pFlT5Q_xR42H"
      },
      "source": [
        "result=minimize(NLK,x0=[0,0.20],bounds=[[0,1],[0.00, 0.50]])"
      ],
      "execution_count": 115,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mMa5Nm9XR6Zz",
        "outputId": "359c7164-44a9-4856-c7a5-01ef1437f27c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 116,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 77.88000000000001\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([-1.42108547e-06, -1.65599943e+01])\n",
              "  message: b'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'\n",
              "     nfev: 18\n",
              "      nit: 4\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.53999999, 0.5       ])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 116
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "AEtrzbEdR7-P"
      },
      "source": [
        "y=[4, 0, 3, 6, 1, 6, 32, 30, 12, 6]\n",
        "p=np.zeros(10)"
      ],
      "execution_count": 117,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8ALAbHb6R9iG"
      },
      "source": [
        "def NLK(x):\n",
        "    for i in range(10):\n",
        "      p[i]=x[0]/10\n",
        "    p[6]=p[6]+(1-x[0])*5*(17-20*x[1])/(100-100*x[1])\n",
        "    p[7]=p[7]+(1-x[0])*10/(100-100*x[1])\n",
        "    p[8]=p[8]+(1-x[0])*5/(100-100*x[1])\n",
        "    for i in range(10):\n",
        "      p[i]=p[i]*100\n",
        "    L=0\n",
        "    for i in range (10):\n",
        "     L = L+(y[i]-p[i])**2\n",
        "    return L/10"
      ],
      "execution_count": 118,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cr_p4DlUR_H5"
      },
      "source": [
        "result=minimize(NLK,x0=[0.05,0.80],bounds=[[0,1],[0.70, 0.85]])"
      ],
      "execution_count": 119,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "p3GGj-HhSAkt",
        "outputId": "78b0760b-f5d0-4f1c-b538-01baa467d93b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "result"
      ],
      "execution_count": 120,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "      fun: 5.577777777778194\n",
              " hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>\n",
              "      jac: array([ 1.15463195e-05, -2.71782596e-05])\n",
              "  message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n",
              "     nfev: 33\n",
              "      nit: 9\n",
              "   status: 0\n",
              "  success: True\n",
              "        x: array([0.34444447, 0.73423422])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 120
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TY9T-oPgSEoR",
        "outputId": "8c959b7e-971f-45a8-f14f-e41a45b51ad9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        }
      },
      "source": [
        "p"
      ],
      "execution_count": 121,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 3.44444468,  3.44444468,  3.44444468,  3.44444468,  3.44444468,\n",
              "        3.44444468, 31.99999933, 28.11111038, 15.77777753,  3.44444468])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 121
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "hk_jEsARSGVk",
        "outputId": "84b4aac8-6b3c-48ee-ac29-6acaecefcda4",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "np.sum(p)"
      ],
      "execution_count": 122,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "99.99999999999997"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 122
        }
      ]
    }
  ]
}